package models

import "gorm.io/gorm"

type Book struct {
	gorm.Model
	Title  string `gorm:"type:varchar(30);not null;unique" json:"title"`
	Author string `gorm:"type:varchar(10);not null" json:"author"`
	Desc   string `gorm:"type:varchar(30);not null" json:"desc"`
	Img    string `gorm:"type:varchar(100)" json:"img"`
}

func (b *Book) Add() error {
	return DB.Create(&b).Error
}
func (b *Book) GetList() (bo []*Book, err error) {
	err = DB.Find(&bo).Error
	return bo, err
}
